import axios from 'axios';

export default {
    get(params) {
        axios.get(params.url, {
            headers: params.headers || {
                "Content-Type": 'application/json',
            },
            params: params.params || {}
        }).then(res => {
            if (res.status === 200) {
                if (typeof params.success == "function") {

                    params.success(res.data)
                }
            } else {
                if (typeof params.fail == "function") {
                    params.fail(res.status)
                }
            }
        }).catch(error => {
            console.error('请求用户数据出错:', error);
        });
    },
    post(params) {
        axios.post(params.url, params.data, {
            headers: params.headers || {
                "Content-Type": 'application/json',
            }
        }).then(res => {
            if (res.status === 200) {
                if (typeof params.success == "function") {
                    params.success(res.data)
                }
            } else {
                if (typeof params.fail == "function") {
                    params.fail(res.status)
                }
            }
        }).catch(error => {
            console.log(error)
            if (typeof params.fail == "function") {
                params.fail(error)
            }
        });
    }
}